#pragma once
#ifndef ITEM_H
#define ITEM_H

#include "DXUT.h"

#include "../Block.h"

#ifdef RENDER
#include "../HUD.h"
#endif

class Item {
protected:
	DWORD	m_ID;
	DWORD	m_Quantity;
public:
	 Item(DWORD id, DWORD quantity);
	 Item(Item * item);
	 virtual Item * clone() = 0;

	 virtual INT GenerateIndexed(BlockVertex ** pVertex, WORD * pVSize, WORD ** pIndex, WORD * pISize ) = 0;
	 virtual INT Generate(BlockVertex * pVertex, WORD * pSize) = 0;

	 DWORD getID() {return m_ID;};
	 DWORD getQuantity() {return m_Quantity;};

	 void setID(DWORD id) {m_ID = id;};
	 void setQuantity(DWORD quality) {m_Quantity = quality;};

	inline Item& operator += (const int rhs)
	{
		m_Quantity += rhs;
		return *this;
	};

	inline Item& operator -= (const int rhs)
	{
		m_Quantity -= rhs;
		return *this;
	};
};

class ItemBlock : public Item {
protected:
	Block	m_Block;
public:
	 ItemBlock(Block block, DWORD quantity);
	 ItemBlock(ItemBlock * item);
	 Item * clone();

	 Block getBlock() {return m_Block;};

	 INT GenerateIndexed(BlockVertex ** pVertex, WORD * pVSize, WORD ** pIndex, WORD * pISize ) {
		 return m_Block.GenerateIndexed(pVertex, pVSize, pIndex, pISize );
	 };

	 INT Generate(BlockVertex * pVertex, WORD * pSize) {
		 return m_Block.Generate(pVertex, pSize);
	 };
};

class Inventory {
private:
	BYTE			m_Selected;
	BYTE			m_Linewidth;
	BYTE			m_Size;
	Item**			m_Items;
#ifdef RENDER
	//BYTE*			m_HUDCoord;
	HUDDialog*		m_HUD;
	//HUDItem*		m_ItemHUD;
	HUDSelected*	m_SelectionHUD;
#endif
public:
#ifdef RENDER
	Inventory(BYTE width, BYTE size, HUDDialogResourceManager* manager);
	void		OnRender( float fElapsedTime );
#else
	Inventory(BYTE width, BYTE size);
#endif
	~Inventory();

	void		setItem(Item* item, BYTE index);
	void		removeItem( BYTE index );
	void		NullItem( BYTE index );
	Item*		getSelected();
	void		removeSelected();

	void		setSelected(int index);

	Item*		getItemAtIndex(int index);
	BYTE		getSize() {return m_Size;};
	BYTE		getLinewidth() {return m_Linewidth;};
};

#endif